package deom1;

import java.util.Stack;

public class Test1 {

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        System.out.println(myQueue.stack1.size());
        myQueue.peek();
        myQueue.pop();
    }
}
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (empty()) {
            return -1;
        }
        if (!stack2.isEmpty()) {
            return stack2.pop();
        } else {
            int n = stack1.size();
            for (int i = 0; i < n; i++) {
                int val = stack1.pop();
                stack2.push(val);
            }
            return stack2.pop();
        }
    }

    public int peek() {
        if (empty()) {
            return -1;
        }
        if (!stack2.isEmpty()) {
            return stack2.peek();
        } else {
            int n = stack1.size();
            for (int i = 0; i < n; i++) {
                int val = stack1.pop();
                stack2.push(val);
            }
            return stack2.peek();
        }
    }

    public boolean empty() {
        return stack1.isEmpty() && stack2.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
